package yang.VirtualMachine.chapter9.classStruct;

import java.io.IOException;
import java.io.InputStream;

import yang.VirtualMachine.chapter9.Processer;
import yang.VirtualMachine.chapter9.classStruct.constantPool.ConstantPoolProcesser;

/**
 * 由上至下的class文件结构
 * @author xinxin
 */
public final class ClassStructController {
	/** 魔数，cafebabe */
	public static final int Magic_Number = 1;
	/** 小版本,大版本 */
	public static final int Class_Version = 2;
	/** 常量池  */
	public static final int Constant_Pool = 3;
	/** Class 的访问标记  */
	public static final int AccessFlag = 4;
	/** Class 类，父类，和接口  */
	public static final int ClassInfo = 5;
	/** 开始步骤 */
	public static final int Start_Step = Magic_Number;
	/** 结束步骤 */
	public static final int Stop_Step = Constant_Pool;
	
	public static void processController(int step, InputStream input) throws IOException {
		Processer processer = null;
		switch (step) {
		case Magic_Number:
			processer = new MagicNumberProcesser();
			break;
		case Class_Version:
			processer = new ClassVersionProcesser();
			break;
		case Constant_Pool:
			processer = new ConstantPoolProcesser();
			break;
		case AccessFlag:
			processer = new AccessFlagProcesser();
			break;
		case ClassInfo:
			processer = new ClassInfoProcesser();
			break;
		default:
			throw new RuntimeException("wrong step: " + step);
		}
		
		processer.start(input);
		processer.process(input);
		processer.end(input);
	}

}
